package com.byxy.ssm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.byxy.ssm.pojo.Tip;
import com.byxy.ssm.pojo.User;

public interface TipMapper {
	@Delete("delete from tip where tip_id=#{tipId}")
    int delete(Integer tipId);
	@Insert("insert into tip(tip_id,user_id,tab_forum_id,tip_title,tip_content,tip_publishTime,tip_modifyTime,tip_click,tip_isDeleted,tip_isKnot,tip_replies) "
			+ "values(#{tipId},#{userId},#{tabForumId},#{tipTitle},#{tipContent},#{tipPublishtime},#{tipModifytime},#{tipClick},#{tipIsdeleted},#{tipIsknot},#{tipReplies})")
    int insert(Tip tip);

    @Select("select * from tip where tip_id=#{tipId}")
    @Results(id="dataset",value={
    	@Result(id=true,column="tip_id",property="tipId"),
    	@Result(column="user_id",property="userId"),
    	@Result(column="tab_forum_id",property="tabForumId"),
    	@Result(column="tip_title",property="tipTitle"),
    	@Result(column="tip_content",property="tipContent"),
    	@Result(column="tip_publishTime",property="tipPublishtime"),
    	@Result(column="tip_modifyTime",property="tipModifytime"),
    	@Result(column="tip_click",property="tipClick"),
    	@Result(column="tip_isDeleted",property="tipIsdeleted"),
    	@Result(column="tip_isKnot",property="tipIsknot"),
    	@Result(column="tip_replies",property="tipReplies"),
    })
    Tip getById(Integer tipId);
    
    @ResultMap("dataset")
    @Select("select * from tip")
    List<Tip> findAll();
    
    @Update("update tip set tip_title=#{tipTitle},tip_content=#{tipContent},tip_modifyTime=#{tipModifytime},tip_isDeleted=#{tipIsdeleted},tip_isKnot=#{tipIsknot},tip_replies=#{tipReplies} where tip_id=#{tipId}")
    int update(Tip tipId);
    
    @ResultMap("dataset")
    @Select("select * from tip where user_id=#{userId}")
	List<Tip> userForum(Integer userId);
}